/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.rafkind.raytracer;

import com.rafkind.beanxmldeserializer.BeanXMLDeserializer;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author drafkind
 */
public class SceneLoader {
  public static Scene loadFromLocalResource(String path) {
    try {
      InputStream is = SceneLoader.class.getClassLoader().getResourceAsStream(path);
      Map<String, Class<?>> classMap = new HashMap<String, Class<?>>();
      classMap.put("camera", Camera.class);
      classMap.put("light", Light.class);
      classMap.put("plane", Plane.class);
      classMap.put("sphere", Sphere.class);
      classMap.put("texture", Texture.class);
      classMap.put("union", Union.class);
      classMap.put("intersection", Intersection.class);
      classMap.put("box", Box.class);
      return BeanXMLDeserializer.loadFrom(is, Scene.class, classMap);
    } catch (Exception ioex) {
      Logger.getAnonymousLogger().log(
              Level.SEVERE,
              "Trouble loading from " + path,
              ioex);
    }
    return null;
  }
}